<template>
  <el-card class="box-card">
    <div slot="header">
      <span>添加账号</span>
    </div>
    <el-form :model="form" ref="form" class="demo-form-inline" :rules="rules">
      <div class="form">
        <el-form-item label="账号:" prop="account">
          <el-input label="left" v-model="form.account" placeholder="请输入账号"></el-input>
        </el-form-item>

        <el-form-item label="密码:" prop="password">
          <el-input label="left" v-model="form.password" placeholder="请输入密码"></el-input>
        </el-form-item>
      </div>

      <el-form-item label="用户组:">
        <el-select v-model="form.userGroup" placeholder="请选择用户组">
          <el-option label="超级管理员" value="超级管理员"></el-option>
          <el-option label="普通用户" value="普通用户"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-divider></el-divider>
        <el-button type="primary" @click="add">添加</el-button>
        <el-button plain @click="resetting">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
import { userAdd } from '@/api/user.js'
export default {
  data() {
    return {
      form: {
        account: '',
        password: '',
        userGroup:'超级管理员'
      },
      rules: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          // { min: 3, max: 8, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
        ]
      },
    }
  },

  methods: {
      add() {
      this.$refs.form.validate(async result => {
        if (result) {
          let res = await userAdd(this.form)
          console.log('res',res);
          } 
      });


    },
    // 重置
    resetting(){
      this.$refs.form.resetFields();
    },

  }
}
</script>

<style lang="less" scoped>
.form {
  label {
    width: 80px;
  }

  width: 400px;

  div {
    display: flex;

    input {
      margin-left: 5px;
    }

  }


}
</style>